<?php
$this->LoadHelper('ApiHelper');
$ApiHelper = new ApiHelper();

$this->LoadHelper('LogisticsHelper');
$LogisticsHelper = new LogisticsHelper();

$this->LoadHelper('OrderHelper');
$OrderHelper = new OrderHelper();

$check = $ApiHelper->tokenCheck($this->Param);
if(!$check['success']) ErrorMsg::ApiMsg($check['msg'], $check['code']);

switch($this->Param['option']){
    case 'list':
        $express = $LogisticsHelper->logisticsAll(array('`ls_status` = ?' => 'no'));
        if(!empty($express)) foreach($express as $k=>$v){
            $order = $OrderHelper->orderRow($v['ls_oid']);
            $express[$k]['ls_uname'] = $order['o_vip_name'];
        }
        $ApiHelper->logSave('expcuslist', $this->Param);
        ErrorMsg::ApiMsg('请求成功', 0 , $express);
        break;
    case 'expsave':
        $result = $LogisticsHelper->logisticsSave($this->Param);
        if($result['success']){
            $ApiHelper->logSave('expsave', $this->Param);
            ErrorMsg::ApiMsg('处理成功', 0);
        }else{
            ErrorMsg::ApiMsg($result['msg']);
        }
        break;
    case 'expinfo'://物流信息
        $oid = empty($this->Param['oid']) ? ErrorMsg::ApiMsg('参数错误') : $this->Param['oid'];
        //检测订单是否为权限允许内操作
        $order_check = $OrderHelper->checkOrderper($oid, $this->UserConfig['Id']);
        if(!$order_check['success'])                ErrorMsg::ApiMsg ('无权操作', 20000);
        $this->LoadHelper('LogisticsHelper');
        $LogisticsHelper = new LogisticsHelper();
        $logistics = $LogisticsHelper->logisticsRow(array('`ls_oid` = ?' => $oid, '`ls_status` = ?' => 'ok'));
        $this->LoadResurces('aliyun/class.express');
        $express = new Express();
        $result = $express->getInfo($logistics['ls_express_no']);
        ErrorMsg::ApiMsg('获取成功', 0, $result);
        break;
    default :
}